
package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author dell
 * @category java反射
 */
public class ReflectHello {
	public ReflectHello() {
	}

	public void sayHello(String name) {
		System.err.println("hello " + name);
	}

	public static void main(String[] args) throws Exception {

		try {
			ReflectHello refect = (ReflectHello) Class.forName("reflect.ReflectHello").newInstance();
			//refect.sayHello("123");
			//用反射方法实现
			Method method = refect.getClass().getMethod("sayHello",String.class);
			method.invoke(refect, "start");
		} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
